
package com.haiyou.common.binary.writer;

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Date;
import java.util.Map;

import com.haiyou.common.util.string.StringUtils;


/**
 * 
 * 
 * @Description: 二进制写入接口
 * @author xingyuan
 * @date 2022年2月15日 下午5:05:46
 */
public interface Writer {

	default byte[] string2Bytes(String string, Charset charset) throws Exception {
		return StringUtils.string2Bytes(string, charset);
	}

	default byte[] utf82Bytes(String string) throws Exception {
		return string2Bytes(string, StringUtils.UTF8);
	}

	ByteBuffer buffer();

	byte[] array();

	Writer writeBuf(ByteBuffer buffer);

	Writer writeByte(int v);

	Writer writeShort(int v);

	Writer writeInt(int v);

	Writer writeLong(long v);

	Writer writeFloat(float v);

	Writer writeDouble(double v);

	Writer writeBool(boolean v);

	Writer writeChar(char v);

	Writer writeString(String v, Charset charset);

	default Writer writeUTF8(String v) {
		return writeString(v, StringUtils.UTF8);
	}

	Writer writeBytes(byte[] v);

	Writer write$Bytes(Byte[] v);

	Writer writeShorts(short[] v);

	Writer write$Shorts(Short[] v);

	Writer writeInts(int[] v);

	Writer write$Integers(Integer[] v);

	Writer writeLongs(long[] v);

	Writer write$Longs(Long[] v);

	Writer writeFloats(float[] v);

	Writer write$Floats(Float[] v);

	Writer writeDoubles(double[] v);

	Writer write$Doubles(Double[] v);

	Writer writeBooleans(boolean[] v);

	Writer write$Booleans(Boolean[] v);

	Writer writeChars(char[] v);

	Writer write$Chars(Character[] v);

	Writer writeStrings(String[] v);

	<E> Writer writeObject(E obj);

	<E> Writer writeCollection(Collection<E> c, Class<E> cls);

	<K, V> Writer writeMap(Map<K, V> map);

	Writer writeDate(Date date);

	Writer writeEnum(Enum e);

	Writer writeClazz(Class<?> clazz);
}
